package com.ruoyi.web.controller.dongfang;

import java.util.List;

import com.ruoyi.question.domain.DfQuestion;
import com.ruoyi.question.service.IDfQuestionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.question.domain.DfQuestionChild;
import com.ruoyi.question.service.IDfQuestionChildService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 问题答案 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-09-12
 */
@Controller
@RequestMapping("/question/dfQuestionChild")
public class DfQuestionChildController extends BaseController
{
    private String prefix = "question/dfQuestionChild";
	
	@Autowired
	private IDfQuestionChildService dfQuestionChildService;

	@Autowired
	private IDfQuestionService dfQuestionService;

	@RequiresPermissions("question:dfQuestionChild:view")
	@GetMapping()
	public String dfQuestionChild()
	{
	    return prefix + "/dfQuestionChild";
	}
	
	/**
	 * 查询问题答案列表
	 */
	@RequiresPermissions("question:dfQuestionChild:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(DfQuestionChild dfQuestionChild)
	{
		startPage();
        List<DfQuestionChild> list = dfQuestionChildService.selectDfQuestionChildList(dfQuestionChild);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出问题答案列表
	 */
	@RequiresPermissions("question:dfQuestionChild:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DfQuestionChild dfQuestionChild)
    {
    	List<DfQuestionChild> list = dfQuestionChildService.selectDfQuestionChildList(dfQuestionChild);
        ExcelUtil<DfQuestionChild> util = new ExcelUtil<DfQuestionChild>(DfQuestionChild.class);
        return util.exportExcel(list, "dfQuestionChild");
    }
	
	/**
	 * 新增问题答案
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存问题答案
	 */
	@RequiresPermissions("question:dfQuestionChild:add")
	@Log(title = "问题答案", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(DfQuestionChild dfQuestionChild)
	{		
		return toAjax(dfQuestionChildService.insertDfQuestionChild(dfQuestionChild));
	}
	/**
	 * 再次提交问题
	 */
	@Log(title = "再次提交问题答案", businessType = BusinessType.INSERT)
	@PostMapping("/submitAgain/{id}")
	@ResponseBody
	public AjaxResult submitAgain(@PathVariable("id") Long id,DfQuestionChild dfQuestionChild)
	{
		DfQuestion dfQuestion = dfQuestionService.selectDfQuestionById(id);
		dfQuestionChild.setQuestionId(dfQuestion.getId());
		dfQuestionChild.setQuestionType("1");
        //解决问题 如果转到研发人员设置问题状态为研发人员待处理，否则技术人员已处理
		if (dfQuestion.getQuestionState().equals("3") || dfQuestion.getQuestionState().equals("4")) {
			dfQuestion.setQuestionState("3");
		} else {
			dfQuestion.setQuestionState("1");
		}
        dfQuestionService.updateDfQuestion(dfQuestion);
		return toAjax(dfQuestionChildService.insertDfQuestionChild(dfQuestionChild));
	}
	/**
	 * 修改问题答案
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		DfQuestionChild dfQuestionChild = dfQuestionChildService.selectDfQuestionChildById(id);
		mmap.put("dfQuestionChild", dfQuestionChild);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存问题答案
	 */
	@RequiresPermissions("question:dfQuestionChild:edit")
	@Log(title = "问题答案", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(DfQuestionChild dfQuestionChild)
	{		
		return toAjax(dfQuestionChildService.updateDfQuestionChild(dfQuestionChild));
	}
	
	/**
	 * 删除问题答案
	 */
	@RequiresPermissions("question:dfQuestionChild:remove")
	@Log(title = "问题答案", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dfQuestionChildService.deleteDfQuestionChildByIds(ids));
	}
	
}
